//保险分类列表及新增
import apis from '../../http/api/modules/admins/classifysList'
export default {
    namespaced: true,
    state: {
        classsifys: [],
        newClassifys: {},
        total: 10,
        rename: '',
    },
    mutations: {
        //新增
        setClasssifys(state, code) {
            if (code) {
                alert('新增成功')
            } else {
                alert('新增失败')
            }
        },
        //渲染
        renderClasssifys(state, data) {
            if (data.code) {
                state.classsifys = data.data.classifysData
                state.total = data.data.total
            }
        },
        //删除
        deleteOne(state, data) {
            if (data.code) {
                alert('删除成功')
            } else {
                alert('保险种类还有内容不能删除')
            }
        },
        //修改
        changeClassifys(state, data) {
        },
        setRename(state, data) {
            state.rename = data
        }

    },
    actions: {
        //新增保险分类
        async addClassifys(context, newClassifys) {
            let { data } = await apis.addCompanies(
                newClassifys
            );
            context.commit('setClasssifys', data.code)
        },
        //渲染保险分类列表
        async getClassifys(context, msg) {

            let data = await apis.getClassifys(
                msg
            );

            context.commit('renderClasssifys', data.data)
        },
        //删除
        async deleteClassifys(context, _id) {
            let { data } = await apis.deleteClassifys(
                _id
            );
            context.commit('deleteOne', data)
        },
        //修改名称
        async modifyClassifys(context, data) {
            let datas = await apis.modifyClassifys(
                data
            );
            context.commit('changeClassifys', datas)
        },
    }
}